package com.example.yyy

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.InputType
import android.text.TextWatcher
import kotlinx.android.synthetic.main.activity_edit.*

class EditActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit)
        //注意不能直接给EdiText控件的text属性赋值
        //否则会报错Editable与String类型不匹配
        //只能调用setText方法对EdiText控件设置文本
        //et_et_editText.setText("")
        et_et_editText.hint = "qsr"
        //隐藏密码
        et_et_editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_NUMBER_VARIATION_PASSWORD
        //文本变化监听器
        et_et_editText.addTextChangedListener(EditWatcher())
    }
    //内部文本变化监听类
    private inner class EditWatcher : TextWatcher {
        override fun afterTextChanged(s: Editable?) {
            var str = s.toString()
            if (str.indexOf("\r")>=0||str.indexOf("\n")>=0){
                str = str.replace("\r","").replace("\n","")
                et_et_editText.setText(str)
            }
            TODO("Not yet implemented")
        }

        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            TODO("Not yet implemented")
        }

        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            TODO("Not yet implemented")
        }

    }
}